
package com.be.beadmin.design.repository;

import com.be.beadmin.design.entity.ProductBomOverview;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
* @author zmy
* @date 2023-02-22
**/
public interface ProductBomOverviewRepository extends JpaRepository<ProductBomOverview, String>, JpaSpecificationExecutor<ProductBomOverview> {

    ProductBomOverview findProductBomOverviewByIdAndDelete(String id, Integer delete);

    ProductBomOverview findProductBomOverviewById(String id);

    List<ProductBomOverview> findProductBomOverviewByBomCode(String bomCode);

    List<ProductBomOverview> findProductBomOverviewsByBomCodeAndDelete(String bomcode, int delete);


    List<ProductBomOverview> findProductBomOverviewsByProductCodeAndDelete(String productCode, int delete);

    @Query(value = "select topbo from ProductBomOverview topbo where topbo.productCode = ?1 and topbo.delete = ?2 and topbo.version = ?3 and topbo.versionSecond = ?4")
    List<ProductBomOverview> findProductBomOverviewsByProductCodeAndnotequalVersion(String productCode, int delete, int version, int versionsecond);

    @Query(value = "select distinct topbo.material_code from t_om_product_bom_overview topbo where topbo.product_code = ?1 and topbo.is_delete = ?2",nativeQuery = true)
    List<String> findMaterialCodeByProductCodeAndDelete(String productCode, int delete);

    List<ProductBomOverview> findProductBomOverviewsByProductCodeAndAndDelete(String productCode, int delete);


    List<ProductBomOverview> findProductBomOverviewsByProductCodeAndMaterialCodeAndDeleteOrderByVersionDesc(String productCode, String materialCode, int delete);

    void deleteProductBomOverviewsByProductCodeAndDelete(String productCode,int delete);

    List<ProductBomOverview> findProductBomOverviewByProductCodeAndMaterialCodeAndDelete(String productCode, String materialCode , int delete);

    List<ProductBomOverview> findProductBomOverviewsByProductCodeAndBomCodeAndVersionAndMaterialCodeAndPositionNoAndDelete(String standTypeCode,String bomCode, int version,String materialCode, String positionNo, int i);

    List<ProductBomOverview> findProductBomOverviewsByProductCodeAndBomCodeAndVersionAndDelete(String productCode, String bomCode, int version, int i);
}